package mysql

import (
	"newuser/userrpc/userrpc"

	"gorm.io/gorm"
)

type Goods struct {
	gorm.Model
	GoodsTitle string `gorm:"type:varchar(50);not null"`
	GoodsPrice int64  `gorm:"type:int(11);not null"`
	GoodsStock int64  `gorm:"type:int(11);not null"`
	UserId     int64  `gorm:"type:int(11);not null"`
}

func (g *Goods) GoodAdd(db *gorm.DB, id int64) error {
	return db.Debug().Where("id=?", id).Create(g).Error
}

func (g *Goods) FindUserById(db *gorm.DB, id int64) error {
	return db.Debug().Where("id=?", id).Find(g).Error
}

func (g *Goods) GoodsFind(db *gorm.DB, in *userrpc.GoodListRequest) (error, []*userrpc.GoodList) {
	var list []*userrpc.GoodList
	return db.Debug().Model(&Goods{}).Find(&list).Error, nil
	return err, list
}
